package com.vicene.gmail.common.valid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.HashSet;
import java.util.Set;

public class BrandShowStatusListValuesValidator implements ConstraintValidator<BrandShowStatusListValues , Integer> {

    private Set<Integer> set = new HashSet<Integer>();
    public void initialize(BrandShowStatusListValues constraintAnnotation) {
        int [] vals = constraintAnnotation.vals();
        for(int val :vals){
            set.add(val);
        }
    }

    /**
     *
     * @param value 需要校验的值
     * @param context
     * @return
     */
    public boolean isValid(Integer value, ConstraintValidatorContext context) {

        return set.contains(value);
    }
}
